package bigdata.service.impl;

import bigdata.service.BaseService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    protected Mapper<T> mapper;
    
    @Override
    public int save(T entity) {
        return mapper.insertSelective(entity);
    }
    @Override
    public int update(T entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }
    @Override
    public int deleteById(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }
    @Override
    public T getById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }
	@Override
	public List<T> selectAll() {
		return mapper.selectAll();
	}
    @Override
    public List<T> selectByExample(Object example) {
        return mapper.selectByExample(example);
    }
    @Override
    public List<T> selectPageByExample(Object example, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return mapper.selectByExample(example);
    }
}
